﻿package game.account.header {
	import game.objects.GameObject;
	import flash.text.TextField;
	import flash.display.MovieClip;
	
	public class Exp extends GameObject {
		
		private function get mcBarMask():MovieClip	{ return this.getChildByName('barMask')		as MovieClip; }
		private function get mcBar():MovieClip		{ return this.getChildByName('bar')			as MovieClip; }
		private function get tfExp():TextField		{ return this.getChildByName('expText')		as TextField; }
		private function get tfLevel():TextField	{ return this.getChildByName('levelText')	as TextField; }
		
		private var _level:int		= 0;
		private var _need:Number	= 0;
		private var _exp:Number		= 0;
		
		public function Exp():void {
			this.update();
		}
		
		public function set level(value:int):void {
			_level = value;
			
			calcNeedExp();
			
			tfLevel.text = String(_level);
		}
		
		public function set exp(value:Number):void {
			_exp = value;
			
			tfExp.text = String(_exp)+' / '+String(_need);
			
			setBar(percent);
		}
		
		public function get percent():Number {
			if (_need==0) return 0;
			return _exp/_need;
		}
		
		public function update():void {
			level	= config.me.level;
			exp		= config.me.exp;
		}
		
		private function setBar(p:Number):void {
			mcBar.x = mcBarMask.x - mcBarMask.width + p*mcBarMask.width;
		}
		
		private function calcNeedExp():void {
			var arr:Object = config.server.arrayExp;
			if (arr[_level])
				_need = arr[_level];
			else
				_need = 0;
		}
	}
	
}